package cn.wolfcode.controller;


import cn.wolfcode.wolf2w.JsonResult.JsonResult;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.StrategyTheme;
import cn.wolfcode.wolf2w.query.StrategyQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyThemeService strategyThemeService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyQuery qo) {
        Page<Strategy> page = strategyService.query(qo);
        model.addAttribute("page", page);
        //pageinfo:MyBatis插件，操作的是Mysql数据库
        //page：spring-data 的组件，操作的是mongodb数据库
        return "strategy/list";
    }


    //添加功能
    @RequestMapping("/input")
    public String input(Model model, String id) {

        model.addAttribute("themes", strategyThemeService.list());
        model.addAttribute("catalogs", strategyCatalogService.groupList());
        if (StringUtils.hasLength(id)){
            model.addAttribute("strategy",strategyService.get(id));
        }
        //strategy
        //catalogs
        //themes
        return "strategy/input";
    }

    @ResponseBody
    @RequestMapping("/changeState")
    public Object changeState(String id, int state) {
        strategyService.changeState(id, state);
        return JsonResult.success();
    }



}
